part of base.utils;

var locate = ['en_US', 'zh_CN'];
var fallbackLocale = Locale('en', 'US');

abstract class ILangInstall {
  Map<String, Map<String, String>> install();
}

Translation initLang(List<ILangInstall> provide) {
  //合并所有子模块的语音
  Map<String, Map<String, String>> langMaps = {};
  locate.forEach((lang) {
    Map<String, String> last = {};
    provide.forEach((element) {
      Map<String, Map<String, String>> langMap = element.install();
      if (langMap.containsKey(lang)) {
        last.addAll(langMap[lang]!);
      }
    });
    langMaps[lang] = last;
  });

  print(langMaps);

  return Translation(langMaps);
}

class Translation extends GetX.Translations {
  Map<String, Map<String, String>> keysMap;

  Translation(this.keysMap);

  Locale? get locale => Get.deviceLocale;

  @override
  Map<String, Map<String, String>> get keys => keysMap;
}
